package com.wonderplay.warlord.module.combat;

import com.wonderplay.warlord.character.Skill;
import com.wonderplay.warlord.engine.CharacterStatus;

public class CharacterCombatStatus {

	CharacterStatus charStatus;

	int currentHealth;
	int[] currentElement;

	public CharacterCombatStatus(CharacterStatus charStatus) {
		this.charStatus = charStatus;

		currentHealth = charStatus.getMaxHealth();
		currentElement = new int[charStatus.getElementNum()];
		
	}

	public void changeCurrentHealth(int health) {
		currentHealth += health;
		currentHealth = currentHealth <= charStatus.getMaxHealth() ? currentHealth
				: charStatus.getMaxHealth();
	}

	public void changeElement(int index, int element) {
		if (index < currentElement.length) {
			currentElement[index] += element;
			currentElement[index] = currentElement[index] <= charStatus
					.getMaxElementByIndex(index) ? currentElement[index]
					: charStatus.getMaxElementByIndex(index);
			currentElement[index] = currentElement[index] >= 0 ? currentElement[index]
					: 0;
		}
	}

	public String toString(){
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("health:").append(currentHealth).append(";");
		for (int i=0; i<currentElement.length; i++){
			strBuf.append("element" + i);
			strBuf.append(":");
			strBuf.append(currentElement[i]);
			strBuf.append(";");
		}
		return strBuf.toString();
	}
	
	//test code
	public Skill getSkill(){
		return charStatus.getSkill(); 
	}
}
